package jianzhi

func isSubStructure(A *TreeNode, B *TreeNode) bool {
	if A == nil || B == nil {
		return false
	}

	var helper func(*TreeNode, *TreeNode) bool
	helper = func(A, B *TreeNode) bool {
		if B == nil {
			return true
		}
		if A == nil || A.Val != B.Val {
			return false
		}

		return helper(A.Left, B.Left) && helper(A.Right, B.Right)
	}

	return helper(A, B) || isSubStructure(A.Left, B) || isSubStructure(A.Right, B)

}
